package com.example.my.meila.view.fragment.beautychildfrg;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.my.meila.R;
import com.example.my.meila.api.ExceptionHandle;
import com.example.my.meila.entity.MakeUp;
import com.example.my.meila.presenter.MakeUpPresenter;
import com.example.my.meila.view.adapter.beautyadapter.MakeUpAdapter;
import com.example.my.meila.view.adapter.beautyadapter.MakeUpHeadAdapter;
import com.example.my.meila.view.adapter.beautyadapter.MakeUpHeadAdapter2;
import com.example.my.meila.view.impl.MakeUpView;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

;

/**
 * A simple {@link Fragment} subclass.
 */
public class MakeUpFragment extends Fragment implements MakeUpView {
    @BindView(R.id.good_xrv)
    XRecyclerView goodXrv;


    RecyclerView itemGoodRv;
    private List<MakeUp.DataBean.VideosBean> data = new ArrayList<>();
    private List<MakeUp.DataBean.FeedsBean> data1 = new ArrayList<>();


    private List<MakeUp.DataBean.MakeupButtonsBean>data2=new ArrayList<>();
    private List<MakeUp.DataBean.BeautyMakeupsBean>data3=new ArrayList<>();


    private MakeUpAdapter adapter;
    private MakeUpPresenter presenter;

    private MakeUpHeadAdapter adapter2;
    private MakeUpHeadAdapter2 adapter3;


    public static MakeUpFragment newInstance() {

        Bundle args = new Bundle();

        MakeUpFragment fragment = new MakeUpFragment();
        fragment.setArguments(args);
        return fragment;
    }


    public MakeUpFragment() {

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_good, container, false);

        ButterKnife.bind(this, view);
        initView();

        initData();



        return view;
    }

    private void initData() {
        presenter=new MakeUpPresenter(this);
        presenter.getMakeUpData();
    }

    private void initView() {
        this.goodXrv.setLayoutManager(new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL,false));
        this.goodXrv.setAdapter(adapter=new MakeUpAdapter(getContext(),data,data1));


        View view2 = LayoutInflater.from(getContext()).inflate(R.layout.item_beauty_good_rv, goodXrv,false);
//        View view2 = LayoutInflater.from(getContext()).inflate(R.layout.item_beauty_good_rv, null);

        itemGoodRv= (RecyclerView) view2.findViewById(R.id.item_good_rv);
        this.goodXrv.addHeaderView(view2);
        this.itemGoodRv.setLayoutManager(new LinearLayoutManager(getContext(),LinearLayoutManager.HORIZONTAL,false));
        this.itemGoodRv.setAdapter(adapter2=new MakeUpHeadAdapter(getContext(),data2));





        View view3 = LayoutInflater.from(getContext()).inflate(R.layout.item_beauty_good_rv,goodXrv,false);
//        View view3 = LayoutInflater.from(getContext()).inflate(R.layout.item_beauty_good_rv,null);

        itemGoodRv= (RecyclerView) view3.findViewById(R.id.item_good_rv);
//        AbsListView.LayoutParams params = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 160);
//        view3.setLayoutParams(params);
        this.goodXrv.addHeaderView(view3);
        this.itemGoodRv.setLayoutManager(new GridLayoutManager(getContext(),2,GridLayoutManager.HORIZONTAL,false));
        this.itemGoodRv.setAdapter(adapter3=new MakeUpHeadAdapter2(getContext(),data3));

    }

    @Override
    public void onSuccess(MakeUp makeUp) {
        data.addAll(makeUp.getData().getVideos());
        data1.addAll(makeUp.getData().getFeeds());
        adapter.notifyDataSetChanged();

        data2.addAll(makeUp.getData().getMakeup_buttons());
        adapter2.notifyDataSetChanged();
        data3.addAll(makeUp.getData().getBeauty_makeups());
        adapter3.notifyDataSetChanged();

    }

    @Override
    public void onFail(ExceptionHandle.ResponeThrowable e) {

    }

    @Override
    public void onFinish() {

    }
}
